package be.msec.smartcard;

public class Date  {

	private short year;
	private byte day, month;
	
	public Date(byte[] data, byte offset) {
		this.year =(short)( ((data[0 + offset]&0xFF)<<8) | (data[1 + offset]&0xFF) );	//Truckje nodig om van 2 bytes naar 1 short te gaan!
		this.month = data[2 + offset];
		this.day = data[3 + offset];
	}
	
	public boolean RevalidationNeeded(Date d) {
		if((this.year - d.year) != 0) return true;
		if((this.month - d.month) != 0) return true;
		
		byte dayDifference = (byte)(this.day - d.day);
		if(GetAbsoluteValue(dayDifference) >= 2) return true;
		
		return false;
	}
	
	private byte GetAbsoluteValue(byte b) {
		if(b < 0 ) return (byte)(b*-1);
		return b;
	}
}
